#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "textedit.h"
#include <QMdiSubWindow>
#include <QPrinter>
#include <QActionGroup>
#include <QSignalMapper>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_newAction_triggered();
    void on_openAction_triggered();
    void on_saveAction_triggered();
    void on_saveAsAction_triggered();
    void on_printAction_triggered();
    void on_printViewAction_triggered();
    void printPreview(QPrinter* printer);
    void on_undoAction_triggered();
    void on_redoAction_triggered();
    void on_pasteAction_triggered();
    void on_cutAction_triggered();
    void on_copyAction_triggered();
    void on_exitAction_triggered();
    void on_closeAction_triggered();
    void on_closeAllAction_triggered();
    void on_tileAction_triggered();
    void on_cascadeAction_triggered();
    void on_nextAction_triggered();
    void on_previousAction_triggered();
    void setActiveSubWindow(QWidget* widget);
    void on_colorAction_triggered();
    void on_blodAction_triggered();
    void on_italicAction_triggered();
    void on_underLineAction_triggered();
    void on_leftAlignAction_triggered();
    void on_centerAction_triggered();
    void on_rightAlignAction_triggered();
    void on_justifyAction_triggered();
    void on_comboBox_activated(int index);
    void on_fontComboBox_activated(const QString &arg1);
    void on_sizeComboBox_activated(const QString &arg1);

protected:
    void closeEvent(QCloseEvent* event) override;

private:
    void init();    //初始化
    void initFontSize();    //初始化字号组合框
    void initScrollBar();   //初始化滚动条
    void initWindowAction();      //初始化窗体相关action
    void initDocAction();         //初始化文本相关action
    TextEdit* activateWindow();        //获取当前活动窗口
    void setActionStatus(bool b);      //设置action状态
    QMdiSubWindow* findSubWindow(const QString& docName);      //获取文档对应的子窗体
    void addSubWindowAction();         //添加子窗体action

private:
    Ui::MainWindow *ui;
    QActionGroup* actionGroup;      //菜单W中子窗体对应的action
    QSignalMapper* mapper;          //信号映射器
};

#endif // MAINWINDOW_H
